#ifndef _APP_H_
#define _APP_H_

#include "input_judge.h"
#include "list.h"
#include "login.h"
#include "progress_bar.h"
#include "concert_ticket.h"

#define  CORE_BLACK         "\033[30m"
#define  CORE_RED           "\033[31m"
#define  CORE_GREEN         "\033[32m"
#define  CORE_YELLOW        "\033[33m"
#define  CORE_BLUE          "\033[34m"
#define  CORE_WHITE         "\033[37m"
#define  CORE_NONE          "\033[0m"
#define  CLEAN_LINE         "\033[K"                /*清除从光标到行尾的内容*/
#define  REVERSE_SHOW       "\033[7m"               /*反显*/
#define  HIGH_LIGHT         "\033[?25h"             /*显示光标*/
#define  LOW_LIGHT          "\033[?25l"             /*隐藏光标*/


/*Linux下终端C语言控制光标的技巧*/
#define CLEAR()         printf("\033[2J")           /*清除屏幕*/
#define MOVEUP(x)       printf("\033[%dA", (x))     /*上移光标*/
#define MOVEDOWN(x)     printf("\033[%dB", (x))     /*下移光标*/
#define MOVELEFT(y)     printf("\033[%dD", (y))     /*左移光标*/
#define MOVERIGHT(y)    printf("\033[%dC",(y))      /*右移光标*/
#define MOVETO(x,y)     printf("\033[%d;%dH", (x), (y))     /*定位光标*/
#define RESET_CURSOR()  printf("\033[H")            /*光标复位*/
#define HIDE_CURSOR()   printf("\033[?25l")         /*隐藏光标*/
#define SHOW_CURSOR()   printf("\033[?25h")         /*显示光标*/
#define HIGHT_LIGHT()   printf("\033[7m")         
#define UN_HIGHT_LIGHT() printf("\033[27m")

#define MENU_NUM        (8)
#define OPTION_MAX      (10)


/*一个页面里每个选项的数据*/
struct option {
	int option_type;
	int x_position;
	int y_position;
	char name[20];
	char *p_data;
	int data_length;
};

/*一个页面的数据*/
struct menu {
	int option_num;
	int current_option;
	char title[20];
	char temp[20];
	struct option option[OPTION_MAX];
};

/*整个售票系统的数据*/
struct app {
	struct list_head ticket_head;
	struct list_head booked_ticket_id_head;
	struct user_info  user_info_data;
	struct login_info login_info_data;
	struct menu menu_data[MENU_NUM];
};

enum menu_options {
	MAIN_MENU = 0,
	LOGIN_MENU,
	REGISTER_MENU,
	SECOND_MENU,
	BOOK_RETURN_TICKET,
	OWNING_TICKET,
	BACK_MAIN_MENU,
	BACK_SECOND_MENU,
	EXIT
};

#define HAVE_DATA   (1)
#define NO_DATA     (0)

#define PARAMETER_ERROR   (1)

typedef int (*menu_funtion_p_t)(struct app *);

extern struct app *init(menu_funtion_p_t *menu_funtion_p);
extern int run(struct app *app_p, menu_funtion_p_t *menu_funtion_p);
extern int destroy(struct app *app_p, menu_funtion_p_t *menu_funtion_p);

#endif
